home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / incl / LEDA / impl / bb_tree.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  1.7 KB  |  82 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  bb_tree.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16. #ifndef LEDA_BB_TREE_H
  17. #define LEDA_BB_TREE_H
  18.  
  19. //------------------------------------------------------------------------------
  20. //
  21. // bb_tree:  
  22. //
  23. //           derived from class "bin_tree"
  24. //
  25. // Ijon Tichy (1993)
  26. //
  27. //------------------------------------------------------------------------------
  28.  
  29.  
  30. #include <LEDA/basic.h>
  31. #include <LEDA/impl/bin_tree.h>
  32.  
  33.  
  34. typedef bin_tree_node* bb_tree_item;
  35.  
  36.  
  37. // ----------------------------------------------------------------
  38. // class bb_tree
  39. // ----------------------------------------------------------------
  40.  
  41. // const float alpha = 0.28;
  42. // const float d     = 0.58;
  43.  
  44. // we multiply alpha, d, and all balances by 64 to make them integers
  45.  
  46.   const int alpha = 18; // 0.28 * 64
  47.   const int d = 37;     // 0.58 * 64
  48.  
  49. class bb_tree : public virtual bin_tree
  50.  
  51.   int root_balance() { return 2; }
  52.   int node_balance() { return 2; }
  53.   int leaf_balance() { return 1; }
  54.  
  55.   void rebal(bb_tree_item,int);
  56.   void insert_rebal(bb_tree_item);
  57.   void del_rebal(bb_tree_item, bb_tree_item);
  58.  
  59.  
  60.   float balance(bb_tree_item p)
  61.   { if (p->is_leaf()) 
  62.        return 0.5 ;
  63.     else 
  64.        return float(p->child[left]->get_bal())/p->get_bal();
  65.    }
  66.  
  67. public:
  68.  
  69.   bb_tree() {}
  70.  ~bb_tree() {}
  71.  
  72.   bb_tree(const bb_tree& T) : bin_tree(T) {}
  73.  
  74.   bb_tree& operator=(const bb_tree& T) 
  75.   { bin_tree::operator=(T); return *this; }
  76.  
  77. };
  78.  
  79. #endif
  80.